/* eslint-disable eol-last */
/* eslint-disable indent */
'use strict';
module.exports = app => {
    class AtMeController extends app.Controller {
        // async  异步是promise的语法糖
        async index() {
            // 获取session
            const { id: userId } = this.ctx.session.getUserInfo;
            // 1.获取atMe我的数量
            const atCount = await this.service.atRelation.getAtCount(userId);
            // 2.获取atMe的微博列表
            const result = await this.service.atRelation.getAtMeBlogList({ userId, pageIndex: 0, pageSize: 10 });
            await this.ctx.render('atMe.html', {
                blogList: result.blogList,
                count: result.count,
                pageIndex: 1,
                pageSize: 10,
                atCount,
            });
            // 将atMe变成已读
            await this.service.atRelation.update({ newIsRead: true }, { userId, isRead: false });
        }
    }
    return AtMeController;
};